package com.leetcode.No0477;

/**
 * @program: leetcode
 * @description:
 * @author: wangzhihua
 * @date: 2021-05-29
 */
public class Solution {
	public int totalHammingDistance(int[] nums) {
		int len = nums.length;
		int tmpNum;
		int ans = 0;
		for (int i = 0; i < len; ++i) {
			for (int j = i + 1; j < len; ++j) {
				if (i == j) {
					continue;
				}
				tmpNum = nums[i] ^ nums[j];
				while (tmpNum > 0) {
					if ((tmpNum & 1) == 1) {
						++ans;
					}
					tmpNum >>= 1;
				}
			}
		}

		return ans;
	}
}
